package com.zhongxi.guoyuan.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.zhongxi.guoyuan.R;
import com.zhongxi.guoyuan.entity.user.center.MessageData;

import java.util.List;

/**
 * Created by Administrator on 2016/12/16.
 */

public class MessageAdapter extends BaseAdapter {

    private Context context;
    private List<MessageData> list;

    public MessageAdapter(Context context, List<MessageData> data) {
        this.context = context;
        this.list = data;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if(convertView == null){
            holder = new ViewHolder();
            convertView = LayoutInflater.from(context).inflate(R.layout.item_message, parent, false);
            holder.tvTitle = (TextView) convertView.findViewById(R.id.tvTitle);
            holder.tvTime = (TextView) convertView.findViewById(R.id.tvTime);
            holder.tvContent = (TextView) convertView.findViewById(R.id.tvContent);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        MessageData data = list.get(position);
        if(null!=data.getTitle()&&!"".equals(data.getTitle())){
            holder.tvTitle.setText(data.getTitle());
        }else{
            holder.tvTitle.setText("");
        }
        if(null!=data.getCtime()&&!"".equals(data.getCtime())){
            holder.tvTime.setText(data.getCtime());
        }else{
            holder.tvTime.setText("");
        }
        if(null!=data.getDescription()&&!"".equals(data.getDescription())){
            holder.tvContent.setText(data.getDescription());
        }else{
            holder.tvContent.setText("");
        }
        return convertView;
    }

    class ViewHolder{
        private TextView tvTitle;
        private TextView tvTime;
        private TextView tvContent;
    }
}
